<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>拣货任务管理</title>
		<script type="text/javascript">
	var backupTaskCode = "";
	var username = "";
	$(function() {
		$("#inputForm").validate(); //为inputForm注册validate函数
		$("#beginTimeStr").datepicker({
			format : 'yyyy-mm-dd'
		});
		$("#endTimeStr").datepicker({
			format : 'yyyy-mm-dd'
		});

	});

	function initPrinter(item, arg1) {
		backupTaskCode = item;
		username = arg1;
		var indexLength = getPrinterCount();
		var tempString = "";
		for ( var i = 0; i < indexLength; i++) {
			var name = getPrinterName(i);
			tempString += "<option value='"+name+"'>" + name + "</option>";
		}
		$("#printerBody").html(tempString);
	}

	//获得打印机的个数
	function getPrinterCount() {
		LODOP = getLodop(document.getElementById('LODOP_OB'), document
				.getElementById('LODOP_EM'));
		return LODOP.GET_PRINTER_COUNT();
	};

	//根据打印机序号获得打印机名称
	function getPrinterName(iPrinterNO) {
		LODOP = getLodop(document.getElementById('LODOP_OB'), document
				.getElementById('LODOP_EM'));
		return LODOP.GET_PRINTER_NAME(iPrinterNO);
	};

	function getDate() {
		var d = new Date();
		var vYear = d.getFullYear();
		var vMon = d.getMonth() + 1;
		var vDay = d.getDate();
		var h = d.getHours();
		var m = d.getMinutes();
		var se = d.getSeconds();
		s = vYear + "-" + (vMon < 10 ? "0" + vMon : vMon) + "-"
				+ (vDay < 10 ? "0" + vDay : vDay) + " "
				+ (h < 10 ? "0" + h : h) + ":" + (m < 10 ? "0" + m : m) + ":"
				+ (se < 10 ? "0" + se : se);
		return s;
	}

	function clickPrinter() {
		ajaxPrintBackupTaskSkus();
	}

	function ajaxPrintBackupTaskSkus() {
		$
				.ajax({
					type : 'post',
					url : '${ctx}/backupTask/ajaxPrintBackupTaskSkus',
					data : 'backupTaskCode=' + backupTaskCode,
					dataType : 'json',
					success : function(data) {
						if (data.status == "1") {
							var printName = $("#printerBody").val();

							var stringTemp = "<table width=\"100%\">";
							stringTemp += "<tr>";
							stringTemp += " <td width=\"33%\">去往网点:"
									+ data.batchTask.areaGroupName + "</td>";
							stringTemp += "<td width=\"33%\">订单数量："
									+ data.backupTask.ordenoQty + "</td>";
							stringTemp += " <td width=\"33%\">批次类型："
									+ data.batchTask.type + "</td>";
							stringTemp += " </tr>";
							stringTemp += " <tr>";
							stringTemp += " <td width=\"33%\">拣货单号："
									+ backupTaskCode + "</td>";
							stringTemp += "<td width=\"33%\">姓名：" + username
									+ "</td>";
							stringTemp += " <td width=\"33%\">生成日期:"
									+ getDate() + "</td>";
							stringTemp += " </tr>";
							stringTemp += " <tr>";
							stringTemp += "  <td width=\"33%\">拣货单类型:"+data.batchTask.batchType+"</td>";
							stringTemp += " <td width=\"33%\">商品数量："+data.backupTask.skuQty+"</td>";
							stringTemp += "<td width=\"33%\"></td>";
							stringTemp += " </tr>";
							stringTemp += "</table>";

							stringTemp += "<table width='100%' border='1' cellspacing='0' style='font-size:14px;'><thead><tr><th>商品编号</th><th>数量</th><th>商品信息</th><th>库位信息</th><th>备注</th></tr></thead><tbody>";
							$
									.each(
											data.content,
											function(i) {
												stringTemp += "<tr><td>"
														+ data.content[i].skuId
														+ "</td><td>"
														+ data.content[i].realQty
														+ "</td>";
												stringTemp += "<td>"
														+ data.content[i].backupTaskDTO.skuName
														+ "</td><td>"
														+ data.content[i].backupTaskDTO.storeCode
														+ "</td><td>"+data.content[i].backupTaskDTO.skuString+"</td></tr>";
											});
							stringTemp += "</tbody></table>";
							printExpress(printName, stringTemp, backupTaskCode);
							alert("打印机加载完毕！");
						} else {
							alert(data.content);
						}

					},
					error : function() {
						alert("获取信息错误,打印失败！");
					}
				});
	}

	function printExpress(printName, content, taskName) {
		LODOP = getLodop(document.getElementById('LODOP_OB'), document
				.getElementById('LODOP_EM'));
		LODOP.PRINT_INIT(taskName);
		strCenterStyle = "<style/>form {text-align: center}</style>";
		LODOP.ADD_PRINT_HTM(10, 10, "100%", "100%", strCenterStyle + content);
		if (LODOP.SET_PRINTER_INDEXA(printName)) {
			LODOP.PRINT();
		}
	}

	$(function() {
		$("#beginTimeStr").datepicker().on(
				'changeDate',
				function() {
					$("#inputForm").attr("action",
							"${ctx}/backupTask/backupTaskLists/" + this.value);
					$("#inputForm").submit();
				});
	});

	function backupTaskLists() {
		var time = $("#beginTimeStr").val();
		if (time == "") {
			$("#inputFormTwo").attr("action",
					"${ctx}/backupTask/backupTaskLists/pending");
		} else {
			$("#inputFormTwo").attr("action",
					"${ctx}/backupTask/backupTaskLists/" + time);
		}

		$("#inputFormTwo").submit();
	}
</script>
	</head>
	<body>
		<div id="message" class="alert alert-success" style="display: none;">
			<span id="content"></span>
		</div>
		<div id="fullbg"></div>
		<div id="dialog">
			<div>
				<img src="${ctx }/static/022.gif"></img>
			</div>
		</div>
		<div class="row">
			<form method="post" id="inputForm" class="form-search">
				<label>
					时间:
				</label>
				<input type="text" id="beginTimeStr" value="${from}"
					class="input-large required" />
			</form>

			<form method="post" id="inputFormTwo" class="form-search">
				<label>
					类型:
				</label>
				<select name="search_EQ_type" class="input-medium" id="lineType">
					<option
						<c:if test="${param.search_EQ_type eq 'single'}"> selected</c:if>
						value="single">
						单件
					</option>
					<option
						<c:if test="${param.search_EQ_type eq 'multiple' }"> selected</c:if>
						value="multiple">
						多件
					</option>
					<option
						<c:if test="${param.search_EQ_type eq 'forward' }"> selected</c:if>
						value="forward">
						中转发
					</option>
				</select>
				<label>
					姓名:
				</label>
				<input type="text" id="username"
					value="${param.search_LIKE_username}" name="search_LIKE_username"
					class="input-large required" />
				<button type="button" onclick="backupTaskLists(this);" class="btn">
					查询
				</button>

			</form>
		</div>
		<table id="contentTable"
			class="table table-striped table-bordered table-condensed">
			<thead>
				<tr>
					<th>
						编号
					</th>
					<th>
						订单数量
					</th>
					<th>
						商品数量
					</th>
					<th>
						商品种类
					</th>
					<th>
						类别
					</th>
					<th>
						批次类型
					</th>
					<th>
						操作人
					</th>
					<th>网点</th>
					<th>
						状态
					</th>
					<th>
						操作
					</th>
				</tr>
			</thead>
			<c:if test="${status eq 1 }">
				<tbody>
					<c:forEach items="${object}" var="obj">
						<tr>
							<td>
								${obj.backupTaskCode }
							</td>
							<td>
								<a href="${ctx }/backupTask/showOrdenos/${obj.backupTaskCode}">${obj.ordenoQty
									}</a>

							</td>
							<td>
								${obj.skuQty }
							</td>
							<td>
								${obj.skuType }
							</td>
							<td>
								<c:if test="${obj.type eq 'single' }">
							         单件
							</c:if>
								<c:if test="${obj.type eq 'multiple' }">
							            多件
							</c:if>
								<c:if test="${obj.type eq 'forward' }">
							  中转发
							</c:if>
							</td>
							<td>
								<c:if test="${obj.batchType eq 'zwarehouse'}">
									<span class="label label-success">总仓订单</span>
								</c:if>
								<c:if test="${obj.batchType eq 'fwarehouse'}">
									<span class="label label-important">分仓订单</span>
								</c:if>
							</td>
							<td>
								${obj.username }
							</td>
							<td>
						 ${obj.areaGroupName }
						</td>
							<td>

								<c:choose>
									<c:when test="${obj.type eq 'forward' }">
										<span class="label label-success"> 打单</span>
									</c:when>
									<c:otherwise>
										<c:if test="${obj.pickStatus eq 'finish' }">
											<span class="label label-success"> 拣货完成</span>
										</c:if>
										<c:if test="${obj.pickStatus eq 'pending' }">
											<span class="label label-importment">未拣货</span>
										</c:if>
									</c:otherwise>
								</c:choose>

							</td>
							<td>
								<c:choose>
									<c:when test="${obj.type eq 'forward' }">
										<a
											href="${ctx }/printBackupTask/printInit/${obj.backupTaskCode}"
											class="btn btn-primary">打印订单</a>
									</c:when>
									<c:otherwise>
										<c:if test="${obj.pickStatus eq 'pending' }">
											<a href="${ctx }/backupTask/pickingSku/${obj.backupTaskCode}"
												class="btn btn-success">拣货</a>
										</c:if>
										<a href="#selextPrinter" role="button" data-toggle="modal"
											class="btn btn-primary"
											onclick="initPrinter('${obj.backupTaskCode}','${obj.username }')">打印拣货单</a>
									</c:otherwise>
								</c:choose>
								<a class="btn" href="${ctx}/backupTask/exportExcel/${obj.backupTaskCode}">导出</a>
								<a class="btn" href="${ctx}/pickBackupTask/toPickPage/${obj.backupTaskCode}">边拣货边装箱</a>
							</td>
						</tr>
					</c:forEach>
				</tbody>
			</c:if>
			<c:if test="${status eq 0 }">
				<tbody>
					<c:forEach items="${object.content}" var="obj">
						<tr>
							<td>
								${obj.backupTaskCode }
							</td>
							<td>
								<a href="${ctx }/backupTask/showOrdenos/${obj.backupTaskCode}">${obj.ordenoQty
									}</a>
							</td>
							<td>
								${obj.skuQty }
							</td>
							<td>
								${obj.skuType }
							</td>
							<td>
								<c:if test="${obj.type eq 'single' }">
							     单件
							</c:if>
								<c:if test="${obj.type eq 'multiple' }">
							  多件
							</c:if>
								<c:if test="${obj.type eq 'forward' }">
							  中转发
							</c:if>
							</td>
							<td>
								<c:if test="${obj.batchType eq 'zwarehouse'}">
									<span class="label label-success">总仓订单</span>
								</c:if>
								<c:if test="${ obj.batchType eq 'fwarehouse'}">
									<span class="label label-important">分仓订单</span>
								</c:if>
							</td>
							<td>
								${obj.username }
							</td>
							<td>
						 ${obj.areaGroupName }
						</td>
							<td>
								<c:if test="">
									<c:if test="${obj.pickStatus eq 'finish' }">
										<span class="label label-success"> 拣货完成</span>
									</c:if>
									<c:if test="${obj.pickStatus eq 'pending' }">
										<span class="label label-importment">还未拣货</span>
									</c:if>
								</c:if>
							</td>
							<td>
								<c:choose>
									<c:when test="${obj.type eq 'forward' }">
										<a
											href="${ctx }/printBackupTask/printInit/${obj.backupTaskCode}"
											class="btn btn-primary">打印订单</a>
									</c:when>
									<c:otherwise>
										<c:if test="${obj.pickStatus eq 'pending' }">
											<a href="${ctx }/backupTask/pickingSku/${obj.backupTaskCode}"
												class="btn btn-success">拣货</a>
										</c:if>
										<a href="#selextPrinter" role="button" data-toggle="modal"
											class="btn btn-primary"
											onclick="initPrinter('${obj.backupTaskCode}','${obj.username }')">打印拣货单</a>
									</c:otherwise>
								</c:choose>
								<a class="btn" href="${ctx}/backupTask/exportExcel/${obj.backupTaskCode}">导出</a>
								
								<a class="btn" href="${ctx}/pickBackupTask/toPickPage/${obj.backupTaskCode}">边拣货边装箱</a>
							</td>
						</tr>
					</c:forEach>
				</tbody>
			</c:if>
		</table>
		<div style="display: none; width: 1000" class="modal hide fade"
			tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
			aria-hidden="true" id="selextPrinter">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">
					×
				</button>
				<h3 id="printerNumber">
					选择打印机
				</h3>
			</div>
			<div class="modal-body">
				<select id="printerBody" name="printerBody">
				</select>
			</div>
			<div class="modal-footer">

				<button class="btn" data-dismiss="modal" aria-hidden="true"
					id="printer" onclick="clickPrinter()">
					开始打印
				</button>

				<button class="btn" data-dismiss="modal" aria-hidden="true">
					Close
				</button>
			</div>
		</div>
		<c:if test="${status eq 0 }">
			<tags:pagination page="${object}" paginationSize="5" />
		</c:if>
	</body>
</html>